package com.hzhr.iot.user.dao;

import com.hzhr.iot.user.dao.mapper.custom.UserInRoleEntityCustomMapper;
import com.hzhr.iot.user.dao.mapper.generator.UserInRoleEntityMapper;
import com.hzhr.iot.user.entity.UserInRoleEntity;
import com.hzhr.iot.user.entity.ext.UserInRoleEntityExt;
import com.hzhr.iot.user.queryModel.custom.UserInRoleCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class UserInRoleDao {
    @Autowired
    UserInRoleEntityMapper userInRoleEntityMapper;
    @Autowired
    UserInRoleEntityCustomMapper userInRoleEntityCustomMapper;

    public int insert(UserInRoleEntity record) {
        if (record == null) return 0;
        int changeCount = userInRoleEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(UserInRoleCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = userInRoleEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(UserInRoleEntity record) {
        if (record == null) return 0;
        int changeCount = userInRoleEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public UserInRoleEntity selectEntity(UserInRoleCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<UserInRoleEntityExt> extList = userInRoleEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<UserInRoleEntity> selectEntityList(UserInRoleCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<UserInRoleEntityExt> extList = userInRoleEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<UserInRoleEntity> entityList = new ArrayList<>();
        for (UserInRoleEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public UserInRoleEntityExt selectExt(UserInRoleCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<UserInRoleEntityExt> extList = userInRoleEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<UserInRoleEntityExt> selectExtList(UserInRoleCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<UserInRoleEntityExt> extList = userInRoleEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(UserInRoleCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = userInRoleEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
